#!/usr/bin/env node

const http = require('http');
const log = console.log;
http.createServer((req,res)=>{

  log('请求起始行'+`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  log('请求头'+req.headers);
  log('----------------------------------------------------');
  log('User-Agent:'+req.headers['User-Agent']);
  log('Host:'+req.headers.host;
  log('Content-Type:'+req.headers['Content-Type']);
  log('----------------------------------------------------');

  log('authorization:'+req.headers.authorization)

  let auth = req.headers.authorization;

  if(typeof auth !== 'undefined'){
    auth.split(' ');
    if(auth[0] === 'Basic'){
      let buf = new Buffer(auth[1],'base64');
      log('username & password',buf.toString('utf8'));
    }
  }
  res.end('OK')
}).listen(8080);
